﻿
namespace Mulala.Cavan.Presentation.Seedwork
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.Contracts;
    using System.Globalization;
    using System.Linq;
    using System.Text;
    using System.Web.Mvc;
    using System.Web.Routing;
    using Mulala.Cavan.Core;
    using Mulala.Cavan.Core.Persistent;
    using Mulala.Cavan.Application.Seedwork;

    public abstract class ReadController<T, TID, TSearch, TModel, TAppService>
        : WebController<TModel>, IEntityController<TModel, TAppService>
        where T : class, IPersistentObjectWithTypedId<TID>
        where TModel : class, IEditModel<T, TID, TSearch>
        where TAppService : class, IReadAppService<T, TID, TSearch>
        where TSearch : class,ISearch<TID>, new()
    {
        #region members
        TAppService _appService;
        #endregion

        #region init
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);
        }
        #endregion

        #region properties Facade & Model
        public TAppService AppService
        {
            get
            {
                _appService.Messages = Model.Messages;
                return _appService;
            }
            set
            {
                _appService = value;
            }
        }
        #endregion

        #region protected OnBind
        protected virtual bool OnBindSearch()
        {
            var result = BindModel(Model.SearchParam);

            return result;
        }
        #endregion protected OnBind
    }
}